<?php
namespace ApiBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use ApiBundle\Controller\ApiCommonController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use CommonBundle\Controller\IAuth;
use Symfony\Component\HttpFoundation\Response;


/**
 * Class ApiUserController
 * @package ApiBundle\Controller
 */
class ApiUserController extends ApiCommonController{

    /**
     * @abstract 获取所有的用户数据
     * @Route("/adminuser/all",name="adminuser_all")
     */
    function getAllUserData(Request $request){
        //测试的加密字符串CWiITprQoEy5FpKGjcKUxj9ItGrdBCMy2gAOTgub4oM=
        //测试加密传参数组
//        $arrData = [
//            'id'=>'1',
//            'did'=>'111212112'
//        ];
        //验证数据请求头
        $_CheckInfo = $this->checkHeaderInfo($request);
        //使用json转码
        $_objCheckInfo = json_decode($_CheckInfo);
        if($_objCheckInfo->status == '0'){//数据验证失败
            $_strReturn = $this->get('common_service')->apiEnCode($_objCheckInfo->status,$_objCheckInfo->message,[],400);
            return new Response($_strReturn);
        }else if($_objCheckInfo->status == '1'){//请求数据验证成功
            //在数据验签成功的情况下使用redis记录一下请求中的验签的sign值，作为下一次验签的验证准备
            $_boolSaveSignByRedis = $this->get('common_service')->saveSignByRedis($request);
            if($_boolSaveSignByRedis){//标识存储成功，下一步及时查询实际的数据了
                $_strReturn = $this->get('common_service')->apiEnCode($_objCheckInfo->status,$_objCheckInfo->message,[],200);
            }else{
                $_strReturn = $this->get('common_service')->apiEnCode('0','sign已失效或存储失败',[],400);
            }
            return new Response($_strReturn);
        }
    }


    /**
     * @abstract 测试路由
     * @Route("/adminuser/test",name="adminuser_test")
     */
    function test(Request $request){
        //验证数据请求头
        $arrData = [
            'id' => '1',
            'did' =>'123123123',
            'time' => $this->get('common_service')->get13TimeStamp()
        ];

        //加密数据VjCFzLBaPLjoSWPYVho0BO0ZP7YBh3tENkvvzsRp+DRmnFEl0iHueoGCj0C0RDVFhkNVqtX8RHttsPpGJqXtiA==
        $_strSign = $this->get('common_service')->encryptSign($arrData);
        echo $_strSign;exit;
    }


}